package com.angola.sms.extipetrpide

import android.content.ContextWrapper
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.FragmentActivity

fun View.dip2Pxipetrpide(floatValue: Float): Int {
    val scale = resources.displayMetrics.density
    return (floatValue * scale + 0.5F).toInt()
}

fun View.px2Dipipetrpide(floatValue: Float): Int {
    val scale = resources.displayMetrics.density
    return (floatValue / scale + 0.5F).toInt()
}

fun View.getParentActivityipetrpide(): FragmentActivity? {
    var gcontext = context
    while (gcontext is ContextWrapper) {
        if (gcontext is AppCompatActivity) {
            return (gcontext as FragmentActivity)
        }
        gcontext = gcontext.baseContext
    }
    return null
}

fun View.recordClickEvent(
    remark: String? = System.currentTimeMillis().toString()
) {
    try {
        if (tag != null) {
            var gTag = tag as String
            if (gTag.isNotBlank()) {
                gTag = "CLICK_$gTag"

                var gRemark = remark
                if (gRemark.isNullOrBlank()) {
                    gRemark = System.currentTimeMillis().toString()
                }
//                RiskDataHelpipetrpide.sycPointData(
//                    type = gTag,
//                    remark = gRemark
//                )
            }
        }
    } catch (e: Exception) {
        e.printStackTrace()
    }
}